<<<<<<< HEAD
<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Systemset extends CI_Controller {

    private $tab = 'system';

    function __construct() {
        parent::__construct();
        /** 登陆验证 */
        if (!isset($_SESSION)) {
            session_start();
        }

        $admin = $this->session->userdata('admin_user');
        if (!$admin || !isset($admin['user_id'])) {
            header('Location: /sys_admin/login');
            exit;
        }
    }

    /**
     * SEO设置
     * Enter description here ...
     */
    function seoset() {
        $vdata['tab'] = $this->tab;
        $vdata['sub'] = 'redparameter';
        print_r($vdata);
        die;
    }

    /**
     * 安全参数设置
     * Enter description here ...
     */
    function safeparameter() {
        $vdata['tab'] = $this->tab;
        $vdata['sub'] = 'safeparameter';
        print_r($vdata);
        die;
    }

    /**
     * 安全问题库设置
     */
    function safequestion() {
        $vdata['tab'] = $this->tab;
        $vdata['sub'] = 'safequestion';
        print_r($vdata);
        die;
    }

    /**
     * 
     * 服务费设置
     * $ftype  1：服务费设置 4：邮件通道设置  6：短信设置 7:SEO设置
     */
    function sysparameter() {
        $ftype = intval($this->input->get('ftype'));
        
        if ($ftype != 0) {
            $data['where']['ftype'] = $ftype;
        }
        $per_page = $this->input->get('per_page') ? $this->input->get('per_page') : 0;

        $this->load->model('systemset_model');

        $data['page_size'] = sys_admin_LIST_PAGE_SIZE;
        $data['page_start'] = (int) $per_page;

        $vdata = $this->systemset_model->systemsetlist($data);


        //分页
        $this->load->library('pagination');
        $config['base_url'] = '/sys_admin/systemset/sysparameter/?ftype=' . $ftype;
        $config['total_rows'] = $vdata['sys_count'];
        $config['per_page'] = sys_admin_LIST_PAGE_SIZE;
        $this->pagination->initialize($config);

        $vdata['tab'] = $this->tab;
        
        $ftype = $ftype?$ftype:1; 
        //  $sysparam = array(1 => 'serviceparameter', 4 => 'emailparameter',6 => 'messageparameter', 7 => 'systemseo');
        $vdata['sub'] = 'serviceparameter';
        $sysType = $this->systemset_model->arrays('sys_type');
        
        
        $vdata['chipName'] = $sysType[$ftype];

        $this->load->view('/sys_admin/system/systemset_list', $vdata);
    }

    function addparameter() {
        $this->load->model('systemset_model');
        $act = $this->input->post('act');
        $this->load->model('log_model');

        if (isset($act) && $act) {

            if ($act == 'add') {
                $data = array(
                    'name' => $this->input->post('name'),
                    'nid' => $this->input->post('nid'),
                    'fvalue' => $this->input->post('fvalue'),
                    'ftype'  => $this->input->post('ftype'),
                );

                $systemset_id = $this->systemset_model->add($data);
                $this->log_model->add_log('[添加][系统管理设置]->[' . $data['name'] . ']');
                $this->create_system_file();
                header("location:/sys_admin/systemset/sysparameter");
                exit;
            } else if ($act == 'edit') {
                $id = $this->input->post('id');
                $sysinfo = $this->systemset_model->get_systemset(array('id' => $id));
                $edata = array(
                    'fvalue' => $this->input->post('fvalue'),
                );
                $res = $this->systemset_model->update($id, $edata);

                if ($res > 0) {
                    $this->log_model->add_log('[编辑][系统管理设置]->[' . $sysinfo['name'] . ']');
                    $ret = array('msg' => '操作成功');
                } else {
                    $ret = array('msg' => '操作失败');
                }
            } else if ($act == 'delete') {
                $id = $this->input->post('id');
                $sysinfo = $this->systemset_model->get_systemset(array('id' => $id));

                $ddata = array('is_del' => 1);
                $res = $this->systemset_model->update($id, $ddata);
                if ($res > 0) {
                    $this->log_model->add_log('[删除][系统管理设置]->[' . $sysinfo['name'] . ']');
                    $ret = array('msg' => '操作成功');
                } else {
                    $ret = array('msg' => '操作失败');
                }
            }

            $this->create_system_file();
            echo json_encode($ret);
            exit;
        } else {
            $vdata['tab'] = $this->tab;
            $vdata['sub'] = 'serviceparameter';
            $vdata['sys_type'] = $this->systemset_model->arrays('sys_type');
            $this->load->view('/sys_admin/system/systemset_add', $vdata);
        }
    }

    function sys_synchronize() {
        $this->load->model('systemset_model');
        $id = $this->input->post("id");
        $sysinfo = $this->systemset_model->get_systemset(array('id' => $id));
        $sys_type = $this->systemset_model->arrays('sys_type');
        $sysinfo['ftype'] = $sys_type[$sysinfo['ftype']];

        $ret = array('msg' => $sysinfo);
        echo json_encode($ret);
        exit;
    }

    /**
     * 系统配置
     * @param $id
     */
    public function edit_view() {
        $this->load->helper(array('form'));
        $this->load->model('systemset_model');
        $isset = $this->systemset_model->check_systemset();

        $vdata['tab'] = $this->tab;
        $vdata['sub'] = 'systemset';

        if (false == $isset) {
            $this->load->view("/sys_admin/system/systemset_add", $vdata);
            return;
        }
        $systemset = $this->systemset_model->get_systemset();
        $vdata['systemset'] = $systemset;


        $this->load->view("/sys_admin/system/systemset_edit", $vdata);
    }

    public function add() {

        $data = array(
            'platform_name' => $this->input->post('platform_name'),
            'web_name' => $this->input->post('web_name'),
            'web_url' => $this->input->post('weburl'),
            'webmobile_url' => $this->input->post('webmobileurl'),
            'webbbs_url' => $this->input->post('webbbsurl'),
            'keywords' => $this->input->post('keywords'),
            'description' => $this->input->post('description'),
            'fuwutel400' => $this->input->post('fuwutel400'),
            'fuwutel' => $this->input->post('fuwutel'),
            'compay_name' => $this->input->post('compay_name'),
            'fax' => $this->input->post('fax'),
            'address' => $this->input->post('address')
        );

        if (!file_exists(UPFILES_LOGO_IMG)) {
            mkdir(UPFILES_LOGO_IMG);
        }
        $logoimg = "";
        if ($_FILES['logoimg']['name'] != '') {
            $logoimg = sha1($_SERVER['HTTP_USER_AGENT'] . $_SERVER['REMOTE_ADDR'] . time() . rand());
            $tmpfn = $_FILES['logoimg']['name'];
            $pt = strrpos($tmpfn, ".");
            $retval = substr($tmpfn, $pt + 1, strlen($tmpfn) - $pt);
            $logoimg.="." . $retval;
            $upfile = UPFILES_LOGO_IMG . "/" . $logoimg;
            if (is_uploaded_file($_FILES['logoimg']['tmp_name']))
                move_uploaded_file($_FILES['logoimg']['tmp_name'], $upfile);
        }


        $data['logoimg'] = $logoimg;
        $this->load->model('systemset_model');
        $systemset_id = $this->systemset_model->add($data);

        $this->create_file($data);

        header("location:/sys_admin/systemset/edit_view/");
        $this->load->model('log_model');
        $this->log_model->add_log('[添加][系统管理设置][' . $data['platform_name'] . ']');
        exit;
    }

    function template_file() {
        $vdata['tab'] = $this->tab;
        $vdata['sub'] = 'systemfile';
        $this->load->view("/sys_admin/system/systemset_template", $vdata);
    }

    function create_system_file() {
        $this->load->model('systemset_model');
        $data['limit'] = 'all';
        $vdata = $this->systemset_model->systemsetlist($data);
        $isystem_list = $vdata['sys_list'];

        $data = "<?php" . PHP_EOL;
        foreach ($isystem_list as $isystem) {
            $data .="define('" . strtoupper($isystem['nid']) . "', '" . $isystem['fvalue'] . "');" . PHP_EOL;
        }

        $this->load->helper('file');
        /*if (!write_file('./application/config/constants_site.php', $data, 'w+')) {
            error_log("Unable to write the file", 3, "/var/www/html/test.yunchsoft.com/no.log");
        } else {
            write_file('./application/config/constants_site.php', $data, 'w+');
        }*/

        //echo 'SUCCESS';
    }

    /**
     * 创建文件
     * @param $cont
     */
    //*
    private function create_file($cont) {
        foreach ($cont as $k => $v) {
            $$k = $v;
        }

        $data = "<?php" . PHP_EOL
                . "define('CON_NAME', 				'$platform_name');//平台名称" . PHP_EOL
                . "define('CON_PLATFORMNAME', 		'$platform_name');//平台名称" . PHP_EOL
                . "define('CON_WEBNAME', 			'$web_name');//网站名称" . PHP_EOL
                . "define('CON_WEBURL', 				'http://$web_url');//网站网址" . PHP_EOL
                . "define('CON_WEBURL1', 			'$web_url');//网站网址" . PHP_EOL
                . "define('CON_WEBURL2', 			'$web_url');//网站网址" . PHP_EOL
                . "define('CON_WEBBBSURL', 			'http://$webbbs_url');//bbs网址" . PHP_EOL
                . "define('CON_WEBBBSURL1', 			'$webbbs_url');//bbs网址" . PHP_EOL
                . "define('CON_WEBMOBILEURL', 		'http://$webmobile_url');//手机端网址" . PHP_EOL
                . "define('CON_WEBMOBILEURL1', 		'$webmobile_url');//手机端网址" . PHP_EOL
                . "define('CON_KEYWORDS', 			'$keywords');//网站关键词" . PHP_EOL
                . "define('CON_DESCRIPTION', 		'$description');//网站描述" . PHP_EOL
                . "define('CON_BEIAN', 				'$beian');//网站备案号" . PHP_EOL
                . "define('CON_400FUWUTEL', 			'$fuwutel400');//客户服务热线" . PHP_EOL
                . "define('CON_FUWUTEL', 			'$fuwutel');//客户服务热线" . PHP_EOL
                . "define('CON_FAX', 				'$fax');//传真" . PHP_EOL
                . "define('CON_ADDRESS', 			'$address');//联系地址" . PHP_EOL
                . "define('COMPANY_NAME',            '$compay_name');//公司名称" . PHP_EOL;

        $this->load->helper('file');
        if (!write_file('./application/config/constants_site.php', $data, 'w+')) {
            error_log("Unable to write the file", 3, "/var/ftp/no.log");
        } else {
            write_file('./application/config/constants_site.php', $data, 'w+');
        }
    }

    public function edit() {
        $id = $this->input->post('id');
        $oldlogoimg = $this->input->post('oldlogoimg');
        $data = array(
            'platform_name' => $this->input->post('platform_name'),
            'web_name' => $this->input->post('web_name'),
            'web_url' => $this->input->post('weburl'),
            'webmobile_url' => $this->input->post('webmobileurl'),
            'webbbs_url' => $this->input->post('webbbsurl'),
            'keywords' => $this->input->post('keywords'),
            'description' => $this->input->post('description'),
            'fuwutel400' => $this->input->post('fuwutel400'),
            'fuwutel' => $this->input->post('fuwutel'),
            'compay_name' => $this->input->post('compay_name'),
            'fax' => $this->input->post('fax'),
            'beian' => $this->input->post('beian'),
            'address' => $this->input->post('address')
        );

        if (!file_exists(UPFILES_LOGO_IMG)) {
            mkdir(UPFILES_LOGO_IMG);
        }
        $logoimg = "";
        if ($_FILES['logoimg']['name'] != '') {
            $logoimg = sha1($_SERVER['HTTP_USER_AGENT'] . $_SERVER['REMOTE_ADDR'] . time() . rand());
            $tmpfn = $_FILES['logoimg']['name'];
            $pt = strrpos($tmpfn, ".");
            $retval = substr($tmpfn, $pt + 1, strlen($tmpfn) - $pt);
            $logoimg.="." . $retval;
            $upfile = UPFILES_LOGO_IMG . "/" . $logoimg;
            if (is_uploaded_file($_FILES['logoimg']['tmp_name']))
                move_uploaded_file($_FILES['logoimg']['tmp_name'], $upfile);
        }

        $logoimg = $logoimg ? $logoimg : $oldlogoimg;
        $data['logoimg'] = $logoimg;
        $this->load->model('systemset_model');
        $systemset_id = $this->systemset_model->update($id, $data);

        $this->create_file($data);

        header("location:/sys_admin/systemset/edit_view/" . $id);
        $this->load->model('log_model');
        $this->log_model->add_log('[修改][系统管理设置]->' . $id . '->[' . $data['platform_name'] . ']');
        exit;
    }

    function autopay() {
        $per_page = $this->input->get('per_page') ? $this->input->get('per_page') : 0;
        $this->load->model('Autorepay_model');
        $data['page_size'] = sys_admin_LIST_PAGE_SIZE;
        $data['page_start'] = (int) $per_page;
        $vdata = $this->Autorepay_model->get_auto_repay_list($data);
        //分页
        $this->load->library('pagination');
        $config['base_url'] = '/sys_admin/systemset/autopay/?';
        $config['total_rows'] = $vdata['auto_repay_count'];
        $config['per_page'] = sys_admin_LIST_PAGE_SIZE;
        $this->pagination->initialize($config);

        $this->load->view("/sys_admin/system/auto_repay_list", $vdata);
    }

    function saveautopay() {
        $this->load->model('Autorepay_model');
        $admin = $this->session->userdata('admin_user');
        if (isset($admin['type_id']) && $admin['type_id'] == 1) {
            $parms = array('borrow_id' => $this->input->post("borrow_id"));
            $res = $this->Autorepay_model->add($parms);
            if ($res > 0) {
                $ret = array('msg' => '操作成功');
            } else {
                $ret = array('msg' => '操作失败');
            }
        } else {
            $ret = array('msg' => '对不起，权限不足！');
        }
        echo json_encode($ret);
        exit;
    }

    function removeautopay() {
        $this->load->model('Autorepay_model');
        $admin = $this->session->userdata('admin_user');
        if (isset($admin['type_id']) && $admin['type_id'] == 1) {
            $id = $this->input->post("id");
            $res = $this->Autorepay_model->update($id, array('is_del' => 1));
            if ($res > 0) {
                $ret = array('msg' => '操作成功');
            } else {
                $ret = array('msg' => '操作失败');
            }
        } else {
            $ret = array('msg' => '对不起，权限不足！');
        }

        echo json_encode($ret);
        exit;
    }

}
=======
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Systemset extends CI_Controller {

    private $tab = 'system';

    function __construct() {
        parent::__construct();
        /** 登陆验证 */
        if (!isset($_SESSION)) {
            session_start();
        }

        $admin = $this->session->userdata('admin_user');
        if (!$admin || !isset($admin['user_id'])) {
            header('Location: /sys_admin/login');
            exit;
        }
    }

    /**
     * SEO设置
     * Enter description here ...
     */
    function seoset() {
        $vdata['tab'] = $this->tab;
        $vdata['sub'] = 'redparameter';
        print_r($vdata);
        die;
    }

    /**
     * 安全参数设置
     * Enter description here ...
     */
    function safeparameter() {
        $vdata['tab'] = $this->tab;
        $vdata['sub'] = 'safeparameter';
        print_r($vdata);
        die;
    }

    /**
     * 安全问题库设置
     */
    function safequestion() {
        $vdata['tab'] = $this->tab;
        $vdata['sub'] = 'safequestion';
        print_r($vdata);
        die;
    }

    /**
     * 
     * 服务费设置
     * $ftype  1：服务费设置 4：邮件通道设置  6：短信设置 7:SEO设置
     */
    function sysparameter() {
        $ftype = intval($this->input->get('ftype'));
        
        if ($ftype != 0) {
            $data['where']['ftype'] = $ftype;
        }
        $per_page = $this->input->get('per_page') ? $this->input->get('per_page') : 0;

        $this->load->model('systemset_model');

        $data['page_size'] = sys_admin_LIST_PAGE_SIZE;
        $data['page_start'] = (int) $per_page;

        $vdata = $this->systemset_model->systemsetlist($data);


        //分页
        $this->load->library('pagination');
        $config['base_url'] = '/sys_admin/systemset/sysparameter/?ftype=' . $ftype;
        $config['total_rows'] = $vdata['sys_count'];
        $config['per_page'] = sys_admin_LIST_PAGE_SIZE;
        $this->pagination->initialize($config);

        $vdata['tab'] = $this->tab;
        
        $ftype = $ftype?$ftype:1; 
        //  $sysparam = array(1 => 'serviceparameter', 4 => 'emailparameter',6 => 'messageparameter', 7 => 'systemseo');
        $vdata['sub'] = 'serviceparameter';
        $sysType = $this->systemset_model->arrays('sys_type');
        
        
        $vdata['chipName'] = $sysType[$ftype];

        $this->load->view('/sys_admin/system/systemset_list', $vdata);
    }

    function addparameter() {
        $this->load->model('systemset_model');
        $act = $this->input->post('act');
        $this->load->model('log_model');

        if (isset($act) && $act) {

            if ($act == 'add') {
                $data = array(
                    'name' => $this->input->post('name'),
                    'nid' => $this->input->post('nid'),
                    'fvalue' => $this->input->post('fvalue'),
                    'ftype'  => $this->input->post('ftype'),
                );

                $systemset_id = $this->systemset_model->add($data);
                $this->log_model->add_log('[添加][系统管理设置]->[' . $data['name'] . ']');
                $this->create_system_file();
                header("location:/sys_admin/systemset/sysparameter");
                exit;
            } else if ($act == 'edit') {
                $id = $this->input->post('id');
                $sysinfo = $this->systemset_model->get_systemset(array('id' => $id));
                $edata = array(
                    'fvalue' => $this->input->post('fvalue'),
                );
                $res = $this->systemset_model->update($id, $edata);

                if ($res > 0) {
                    $this->log_model->add_log('[编辑][系统管理设置]->[' . $sysinfo['name'] . ']');
                    $ret = array('msg' => '操作成功');
                } else {
                    $ret = array('msg' => '操作失败');
                }
            } else if ($act == 'delete') {
                $id = $this->input->post('id');
                $sysinfo = $this->systemset_model->get_systemset(array('id' => $id));

                $ddata = array('is_del' => 1);
                $res = $this->systemset_model->update($id, $ddata);
                if ($res > 0) {
                    $this->log_model->add_log('[删除][系统管理设置]->[' . $sysinfo['name'] . ']');
                    $ret = array('msg' => '操作成功');
                } else {
                    $ret = array('msg' => '操作失败');
                }
            }

            $this->create_system_file();
            echo json_encode($ret);
            exit;
        } else {
            $vdata['tab'] = $this->tab;
            $vdata['sub'] = 'serviceparameter';
            $vdata['sys_type'] = $this->systemset_model->arrays('sys_type');
            $this->load->view('/sys_admin/system/systemset_add', $vdata);
        }
    }

    function sys_synchronize() {
        $this->load->model('systemset_model');
        $id = $this->input->post("id");
        $sysinfo = $this->systemset_model->get_systemset(array('id' => $id));
        $sys_type = $this->systemset_model->arrays('sys_type');
        $sysinfo['ftype'] = $sys_type[$sysinfo['ftype']];

        $ret = array('msg' => $sysinfo);
        echo json_encode($ret);
        exit;
    }

    /**
     * 系统配置
     * @param $id
     */
    public function edit_view() {
        $this->load->helper(array('form'));
        $this->load->model('systemset_model');
        $isset = $this->systemset_model->check_systemset();

        $vdata['tab'] = $this->tab;
        $vdata['sub'] = 'systemset';

        if (false == $isset) {
            $this->load->view("/sys_admin/system/systemset_add", $vdata);
            return;
        }
        $systemset = $this->systemset_model->get_systemset();
        $vdata['systemset'] = $systemset;


        $this->load->view("/sys_admin/system/systemset_edit", $vdata);
    }

    public function add() {

        $data = array(
            'platform_name' => $this->input->post('platform_name'),
            'web_name' => $this->input->post('web_name'),
            'web_url' => $this->input->post('weburl'),
            'webmobile_url' => $this->input->post('webmobileurl'),
            'webbbs_url' => $this->input->post('webbbsurl'),
            'keywords' => $this->input->post('keywords'),
            'description' => $this->input->post('description'),
            'fuwutel400' => $this->input->post('fuwutel400'),
            'fuwutel' => $this->input->post('fuwutel'),
            'compay_name' => $this->input->post('compay_name'),
            'fax' => $this->input->post('fax'),
            'address' => $this->input->post('address')
        );

        if (!file_exists(UPFILES_LOGO_IMG)) {
            mkdir(UPFILES_LOGO_IMG);
        }
        $logoimg = "";
        if ($_FILES['logoimg']['name'] != '') {
            $logoimg = sha1($_SERVER['HTTP_USER_AGENT'] . $_SERVER['REMOTE_ADDR'] . time() . rand());
            $tmpfn = $_FILES['logoimg']['name'];
            $pt = strrpos($tmpfn, ".");
            $retval = substr($tmpfn, $pt + 1, strlen($tmpfn) - $pt);
            $logoimg.="." . $retval;
            $upfile = UPFILES_LOGO_IMG . "/" . $logoimg;
            if (is_uploaded_file($_FILES['logoimg']['tmp_name']))
                move_uploaded_file($_FILES['logoimg']['tmp_name'], $upfile);
        }


        $data['logoimg'] = $logoimg;
        $this->load->model('systemset_model');
        $systemset_id = $this->systemset_model->add($data);

        $this->create_file($data);

        header("location:/sys_admin/systemset/edit_view/");
        $this->load->model('log_model');
        $this->log_model->add_log('[添加][系统管理设置][' . $data['platform_name'] . ']');
        exit;
    }

    function template_file() {
        $vdata['tab'] = $this->tab;
        $vdata['sub'] = 'systemfile';
        $this->load->view("/sys_admin/system/systemset_template", $vdata);
    }

    function create_system_file() {
        $this->load->model('systemset_model');
        $data['limit'] = 'all';
        $vdata = $this->systemset_model->systemsetlist($data);
        $isystem_list = $vdata['sys_list'];

        $data = "<?php" . PHP_EOL;
        foreach ($isystem_list as $isystem) {
            $data .="define('" . strtoupper($isystem['nid']) . "', '" . $isystem['fvalue'] . "');" . PHP_EOL;
        }

        $this->load->helper('file');
        /*if (!write_file('./application/config/constants_site.php', $data, 'w+')) {
            error_log("Unable to write the file", 3, "/var/www/html/test.yunchsoft.com/no.log");
        } else {
            write_file('./application/config/constants_site.php', $data, 'w+');
        }*/

        //echo 'SUCCESS';
    }

    /**
     * 创建文件
     * @param $cont
     */
    //*
    private function create_file($cont) {
        foreach ($cont as $k => $v) {
            $$k = $v;
        }

        $data = "<?php" . PHP_EOL
                . "define('CON_NAME',     			'$platform_name');//平台名称" . PHP_EOL
                . "define('CON_PLATFORMNAME', 		'$platform_name');//平台名称" . PHP_EOL
                . "define('CON_WEBNAME', 			'$web_name');//网站名称" . PHP_EOL
                . "define('CON_WEBURL', 				'http://$web_url');//网站网址" . PHP_EOL
                . "define('CON_WEBURL1', 			'$web_url');//网站网址" . PHP_EOL
                . "define('CON_WEBURL2', 			'$web_url');//网站网址" . PHP_EOL
                . "define('CON_WEBBBSURL', 			'http://$webbbs_url');//bbs网址" . PHP_EOL
                . "define('CON_WEBBBSURL1', 			'$webbbs_url');//bbs网址" . PHP_EOL
                . "define('CON_WEBMOBILEURL', 		'http://$webmobile_url');//手机端网址" . PHP_EOL
                . "define('CON_WEBMOBILEURL1', 		'$webmobile_url');//手机端网址" . PHP_EOL
                . "define('CON_KEYWORDS', 			'$keywords');//网站关键词" . PHP_EOL
                . "define('CON_DESCRIPTION', 		'$description');//网站描述" . PHP_EOL
                . "define('CON_BEIAN', 				'$beian');//网站备案号" . PHP_EOL
                . "define('CON_400FUWUTEL', 			'$fuwutel400');//客户服务热线" . PHP_EOL
                . "define('CON_FUWUTEL', 			'$fuwutel');//客户服务热线" . PHP_EOL
                . "define('CON_FAX', 				'$fax');//传真" . PHP_EOL
                . "define('CON_ADDRESS', 			'$address');//联系地址" . PHP_EOL
                . "define('COMPANY_NAME',            '$compay_name');//公司名称" . PHP_EOL;

        $this->load->helper('file');
        if (!write_file('./application/config/constants_site.php', $data, 'w+')) {
            error_log("Unable to write the file", 3, "/var/ftp/no.log");
        } else {
            write_file('./application/config/constants_site.php', $data, 'w+');
        }
    }

    public function edit() {
        $id = $this->input->post('id');
        $oldlogoimg = $this->input->post('oldlogoimg');
        $data = array(
            'platform_name' => $this->input->post('platform_name'),
            'web_name' => $this->input->post('web_name'),
            'web_url' => $this->input->post('weburl'),
            'webmobile_url' => $this->input->post('webmobileurl'),
            'webbbs_url' => $this->input->post('webbbsurl'),
            'keywords' => $this->input->post('keywords'),
            'description' => $this->input->post('description'),
            'fuwutel400' => $this->input->post('fuwutel400'),
            'fuwutel' => $this->input->post('fuwutel'),
            'compay_name' => $this->input->post('compay_name'),
            'fax' => $this->input->post('fax'),
            'beian' => $this->input->post('beian'),
            'address' => $this->input->post('address')
        );

        if (!file_exists(UPFILES_LOGO_IMG)) {
            mkdir(UPFILES_LOGO_IMG);
        }
        $logoimg = "";
        if ($_FILES['logoimg']['name'] != '') {
            $logoimg = sha1($_SERVER['HTTP_USER_AGENT'] . $_SERVER['REMOTE_ADDR'] . time() . rand());
            $tmpfn = $_FILES['logoimg']['name'];
            $pt = strrpos($tmpfn, ".");
            $retval = substr($tmpfn, $pt + 1, strlen($tmpfn) - $pt);
            $logoimg.="." . $retval;
            $upfile = UPFILES_LOGO_IMG . "/" . $logoimg;
            if (is_uploaded_file($_FILES['logoimg']['tmp_name']))
                move_uploaded_file($_FILES['logoimg']['tmp_name'], $upfile);
        }

        $logoimg = $logoimg ? $logoimg : $oldlogoimg;
        $data['logoimg'] = $logoimg;
        $this->load->model('systemset_model');
        $systemset_id = $this->systemset_model->update($id, $data);

        $this->create_file($data);

        header("location:/sys_admin/systemset/edit_view/" . $id);
        $this->load->model('log_model');
        $this->log_model->add_log('[修改][系统管理设置]->' . $id . '->[' . $data['platform_name'] . ']');
        exit;
    }

    function autopay() {
        $per_page = $this->input->get('per_page') ? $this->input->get('per_page') : 0;
        $this->load->model('Autorepay_model');
        $data['page_size'] = sys_admin_LIST_PAGE_SIZE;
        $data['page_start'] = (int) $per_page;
        $vdata = $this->Autorepay_model->get_auto_repay_list($data);
        //分页
        $this->load->library('pagination');
        $config['base_url'] = '/sys_admin/systemset/autopay/?';
        $config['total_rows'] = $vdata['auto_repay_count'];
        $config['per_page'] = sys_admin_LIST_PAGE_SIZE;
        $this->pagination->initialize($config);

        $this->load->view("/sys_admin/system/auto_repay_list", $vdata);
    }

    function saveautopay() {
        $this->load->model('Autorepay_model');
        $admin = $this->session->userdata('admin_user');
        if (isset($admin['type_id']) && $admin['type_id'] == 1) {
            $parms = array('borrow_id' => $this->input->post("borrow_id"));
            $res = $this->Autorepay_model->add($parms);
            if ($res > 0) {
                $ret = array('msg' => '操作成功');
            } else {
                $ret = array('msg' => '操作失败');
            }
        } else {
            $ret = array('msg' => '对不起，权限不足！');
        }
        echo json_encode($ret);
        exit;
    }

    function removeautopay() {
        $this->load->model('Autorepay_model');
        $admin = $this->session->userdata('admin_user');
        if (isset($admin['type_id']) && $admin['type_id'] == 1) {
            $id = $this->input->post("id");
            $res = $this->Autorepay_model->update($id, array('is_del' => 1));
            if ($res > 0) {
                $ret = array('msg' => '操作成功');
            } else {
                $ret = array('msg' => '操作失败');
            }
        } else {
            $ret = array('msg' => '对不起，权限不足！');
        }

        echo json_encode($ret);
        exit;
    }

}
>>>>>>> d47623b610d79a4eeb489500830c00d70933f414
